import http from '@/utils/http'
import axios from 'axios'

export interface UserInfo {
  openid: string
  id: number
  unionid: string
  nickname: string
  head_img: string
  platform: string
  brand: string
  cj_num: number // 剩余抽奖次
  today_share: boolean
}

// #设置昵称
export function UpdateUserInfo(params: { nick: string }) {
  return http.post(`/api/contac/ka-moji/nick`, params)
}

// #用户登录
export async function UserLogin() {
  const channel = sessionStorage.getItem('channel') || ''
  return await axios.post(`/api/contac/ka-moji/user`, {}, {
    headers: {
      channel,
    },
  }).then(res => res?.data.data) as UserInfo
}

// #获取用户信息
export function GetUserInfo() {
  return http.get(`/api/contac/ka-moji/info`).then<UserInfo>(res => res?.data)
}

// #分享关系
export function Share() {
  return http.post(`/api/contac/ka-moji/share`)
}
